package com.wenhai.leetcode.array;

/**
 * @ClassName 剑指Offer03数组中重复的数字
 * @Description: https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/
 * @Author 谢文海
 * @Date 2021/4/5 21:11
 * @Version 1.0
 **/
public class 剑指Offer03数组中重复的数字 {
    public int findRepeatNumber(int[] nums) {
        for (int i = 0; i < nums.length; i++) {
            while (nums[i] != i) {
                if (nums[i] == nums[nums[i]]) {
                    return nums[i];
                }
                int temp = nums[i];
                nums[i] = nums[temp];
                nums[temp] = temp;
            }
        }

        return -1;
    }
}
